﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using PPAP.BO;
using iTextSharp.text.pdf;
using System.IO;
using PPAP.Model;
using System.Configuration;
using ICSharpCode.SharpZipLib.Checksums;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.GZip;

namespace PPAP.Web.Part
{
    public partial class PPARAttachmentTab : PageBase
    {
        public string RID { get; set; }
        public string FJRID { get; set; }
        public string QEFJID { get; set; }
        AttachmentTypeBO typebo = new AttachmentTypeBO();
        PPARBO ppbo = new PPARBO();
        LogBO lbo = new LogBO();
        InapplicableBO ibo = new InapplicableBO();
        SetLevelBO sbo = new SetLevelBO();
        T_FileBO manager = new T_FileBO();
        MailTemplateBO mbo = new MailTemplateBO();
        string FJID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                DataSet ds = typebo.GetList("");
                ddlType.Items.Clear();
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    ddlType.Items.Add(new ListItem(dr["id"].ToString() + "-" + dr["ATTACHMENTTYPE"].ToString(), dr["id"].ToString()));
                }

                DataSet ab = typebo.GetAvailable();
                LoadFileSet3(ab);

                PPAR pp = ppbo.GetModel(int.Parse(Request.QueryString["RID"] == null ? "0" : Request.QueryString["RID"].ToString()));
                if (pp != null)
                {
                    DropDownList1.SelectedValue = pp.SUBMISSIONLEVEL.ToString();
                    rbtNo.Checked = pp.ISSPECIFICATIONS == 0 ? true : false;
                    rbtYes.Checked = pp.ISSPECIFICATIONS == 1 ? true : false;
                    specify.Visible = rbtYes.Checked ? false : rbtNo.Checked ? true : false;
                    txtSpecify.Text = pp.SPECIFY;
                    if (pp.STATUS >= 2 && pp.STATUS != 4)
                    {
                        btnSubmit.Visible = false;
                    }
                    if (pp.Qeuser != CurrentUser.Id&&CurrentUser.UnitId!="0"&&CurrentUser.UnitId!="99")  //不是qe负责人，不能修改附件信息
                    {
                        lblApp.Visible = false;
                        td1.Visible = false;
                        GridView1.Columns[6].Visible = false;
                        td2.Visible = false;
                        GridView2.Columns[6].Visible = false;
                       
                    }
                }
                LoadType(ds);

            }
            if(Request.QueryString["RID"]!=null)
            DropDownList1_SelectedIndexChanged(null, null);
           
            if (Request.QueryString["deid"] != null)
            {
                DeleteFile(Request.QueryString["deid"].ToString());
            }
            if (Request.QueryString["RID"] != null)
                RID = Request.QueryString["RID"].ToString();


            if (Request.QueryString["his"] != null && Request.QueryString["his"].ToString() == "1") //从histroy页面跳转过来
            {
                txtSpecify.Enabled = false;
                ddlType.Enabled = false;
                rbtNo.Enabled = false;
                rbtYes.Enabled = false;
                btnSubmit.Visible = false;
               // lblApp.Visible = false;
                DropDownList1.Enabled = false;
                td1.Visible = false;
                GridView1.Columns[6].Visible = false;
                td2.Visible = false;
                GridView2.Columns[6].Visible = false;
                if (CurrentUser.UnitId == "0")  //供应商查看，不显示后台用户上传的附件
                {
                    GridView2.Visible = false;
                    ta1.Visible = false;
                }

            }
            if (CurrentUser.UnitId != "0" && CurrentUser.UnitId != "99")  //非供应商
            {
                DropDownList1.Enabled = false;
                rbtYes.Enabled = false;
                rbtNo.Enabled = false;
                txtSpecify.Enabled = false;
                td1.Visible = false;
            }
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="fileid"></param>
        private void DeleteFile(string fileid)
        {
            try
            {
                DataSet ds = manager.Getpath(int.Parse(fileid));
                string path = ds.Tables[0].Rows[0]["F_Detail"].ToString();
                DataSet dd = ppbo.GetList(" FJID='" + ds.Tables[0].Rows[0]["F_FILEID"].ToString() + "'");
                if (dd.Tables[0].Rows.Count == 0)
                    dd = ppbo.GetList(" qefjid='" + ds.Tables[0].Rows[0]["F_FILEID"].ToString() + "'");
                if (manager.DeleteFile(fileid))
                {
                    // File.Delete(path);
                    AlertRedirect("Deleted successful", "PPARAttachmentTab.aspx?RID=" + dd.Tables[0].Rows[0]["ID"].ToString());
                }

            }
            catch (Exception)
            {

                throw;
            }
        }

        protected override void SkinControl()
        {
        }

        #region  上传
        protected void btnUpload_Click(object sender, EventArgs e)
        {
            if (Request.QueryString["RID"] != null)
            {
                FJID = Request.QueryString["RID"];
                string FileName = file.FileName;
                if (!string.IsNullOrEmpty(FileName))
                {
                    string extension = System.IO.Path.GetExtension(FileName);//获取文件类型后缀名
                    if ((extension.ToLower() == ".pdf"))
                    {
                        int fileSize = file.PostedFile.ContentLength;
                        if (fileSize == 0)
                        {
                            base.AlertMessage("The file does not exist！");
                        }
                        else
                        {
                            if (true)//限制大小为1M
                            {
                                string time = DateTime.Now.ToString("yyyyMMddHHmmss");
                                string FileNam_Time = "";
                                int FileIndex = FileName.LastIndexOf("\\");
                                string FName = FileName.Substring(FileIndex + 1);
                                FileNam_Time = FName;//日期和名称组合
                                string path = HttpContext.Current.Request.MapPath("../FileUpload/QYRD/" + base.CurrentUser.Name + "/");
                                string url = "../FileUpload/QYRD/" + CurrentUser.Name + "/" + time + FileNam_Time;
                                DirectoryInfo upDir = new DirectoryInfo(path);
                                if (!upDir.Exists)
                                {
                                    upDir.Create();
                                }
                                file.SaveAs(path + FileNam_Time);
                                ///加水印
                                string source = path + FileNam_Time; //模板路径
                                string output = path + time + FileNam_Time; //导出水印背景后的PDF
                                string watermark = "../FileUpload/ShuiYin/" + CurrentUser.Id + ".png";   // 水印图片
                                DirectoryInfo upDir2 = new DirectoryInfo(HttpContext.Current.Request.MapPath("../FileUpload/ShuiYin/"));
                                if (!upDir2.Exists)
                                {
                                    upDir2.Create();
                                }
                                if (File.Exists(watermark)) //如果存在，则删除重新生成
                                {
                                    File.Delete(watermark);
                                }
                                AddShuiYin(base.CurrentUser.Name + "(" + base.CurrentUser.Id + ")" + DateTime.Now.ToString("yyyyMMdd HHmmss"), watermark);
                                bool isSurrcess = PDFWatermark(source, output, MapPath(watermark), 10, 10);
                                if (isSurrcess)
                                    File.Delete(source); //删除原文件
                                //加水印
                                DataInfo(FJID, FileNam_Time, path + time, int.Parse(ddlType.SelectedValue), url, (fileSize / 1024.0).ToString("n") + "kb", "", CurrentUser.Id);
                                ShowData(FJID);
                            }
                        }
                    }
                    else
                    {
                        AlertMessage("Can't upload this file types");
                    }
                }
                else
                {
                    AlertMessage("Please select accessories！");
                }
            }
        }
        #endregion

        #region 添加水印
        /// <summary>
        /// PDF添加水印
        /// </summary>
        /// <param name="inputfilepath"></param>
        /// <param name="outputfilepath"></param>
        /// <param name="ModelPicName"></param>
        /// <param name="top"></param>
        /// <param name="left"></param>
        /// <returns></returns>
        public bool PDFWatermark(string inputfilepath, string outputfilepath, string ModelPicName, float top, float left)
        {
            PdfReader pdfReader = null;
            PdfStamper pdfStamper = null;
            try
            {
                pdfReader = new PdfReader(inputfilepath);

                int numberOfPages = pdfReader.NumberOfPages;

                iTextSharp.text.Rectangle psize = pdfReader.GetPageSize(1);

                float width = psize.Width;

                float height = psize.Height;

                pdfStamper = new PdfStamper(pdfReader, new FileStream(outputfilepath, FileMode.Create));

                PdfContentByte waterMarkContent;

                iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(ModelPicName);

                // image.Width = 200;
                // image.Height = 50;

                image.GrayFill = 20;//透明度，灰色填充
                left = width - image.Width + left;
                //top = height - image.Height - top;
                image.SetAbsolutePosition(left, top);

                //每一页加水印,也可以设置某一页加水印 
                for (int i = 1; i <= numberOfPages; i++)
                {
                    waterMarkContent = pdfStamper.GetUnderContent(i);

                    waterMarkContent.AddImage(image);
                }
                return true;
            }
            catch (Exception ex)
            {
                AlertMessage(ex.Message.Trim());
                return false;
            }
            finally
            {

                if (pdfStamper != null)
                    pdfStamper.Close();

                if (pdfReader != null)
                    pdfReader.Close();
            }
        }
        #endregion

        //添加操作
        private void DataInfo(string F_FileID, string F_Filename, string path, int type, string url, string filesize, string remarks, string upby)
        {
            manager.InsertFile(F_FileID, F_Filename, path, type, url, filesize, remarks, upby, "", "", "");
        }

        #region 绑定已上传附件列表
        private void ShowData(string FileID)
        {
            DataSet ds = manager.GetFileList(FileID);
            if (ds.Tables[0].Rows.Count == 0)
            {
                DataRow dr = ds.Tables[0].NewRow();
                dr["attachmenttype"] = "<font color='red'>No files available</font>";
                dr["sx"] = "0";
                dr["rid"] = "0";
                ds.Tables[0].Rows.Add(dr);
            }
            GridView1.DataSource = ds;
            GridView1.DataBind();
            LoadImg(ds);
        }

        public string ShowAccachmenttype(string sx,string attachmenttype)
        {
            if (sx == "0")
                return attachmenttype;
            else
                return sx + "-" + attachmenttype;
        }

        private void ShowDataQE(string FileID)
        {
            DataSet ds = manager.GetFileList(FileID);
            if (ds.Tables[0].Rows.Count == 0)
            {
                DataRow dr = ds.Tables[0].NewRow();
                dr["attachmenttype"] = "<font color='red'>No files available</font>";
                dr["sx"] = "0";
                ds.Tables[0].Rows.Add(dr);
            }
            GridView2.DataSource = ds;
            GridView2.DataBind();
            LoadImg(ds);
        }
        #endregion

        #region 生成水印图片
        /// <summary>
        /// 生成水印图片
        /// </summary>
        /// <param name="Name"></param>
        /// <param name="Path"></param>
        private void AddShuiYin(string Name, string Path)
        {
            //新建一个bmp图片
            System.Drawing.Image bitmap = new System.Drawing.Bitmap(260, 20);
            //新建一个画板
            System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap);
            //设置高质量插值法
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
            //设置高质量,低速度呈现平滑程度
            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
            //清空画布并以透明背景色填充
            g.Clear(System.Drawing.Color.Transparent);
            //在指定位置并且按指定大小绘制原图片的指定部分
            g.DrawImage(bitmap, new System.Drawing.Rectangle(0, 0, 260, 20),

            new System.Drawing.Rectangle(0, 0, 0, 0),

            System.Drawing.GraphicsUnit.Pixel);
            System.Drawing.Font f = new System.Drawing.Font("宋体", 12);
            System.Drawing.Brush b = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
            g.DrawString(Name, f, b, 2, 2);
            try
            {
                //以jpg格式保存缩略图
                bitmap.Save(MapPath(Path), System.Drawing.Imaging.ImageFormat.Png);
            }
            catch (System.Exception ex)
            {
                AlertMessage(ex.Message.ToString());
            }
            finally
            {
                bitmap.Dispose();
                //bitmap.Dispose();
                g.Dispose();
            }
        }
        #endregion

        #region Image
        /// <summary>
        /// 加载附件类型
        /// </summary>
        /// <param name="ds"></param>
        private void LoadType(DataSet ds)
        {
            string TypeName = "";
            int ID = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                TypeName = dr["ATTACHMENTTYPE"].ToString();
                try
                {
                    ID = int.Parse(dr["rownum"].ToString());
                    ID = int.Parse(dr["sx"].ToString());
                }
                catch (Exception)
                {
                    ID = 0;
                }
                switch (ID)
                {
                    case 1:
                        lblType1.Text = TypeName;
                        break;
                    case 2:
                        lblType2.Text = TypeName;
                        break;
                    case 3:
                        lblType3.Text = TypeName;
                        break;
                    case 4:
                        lblType4.Text = TypeName;
                        break;
                    case 5:
                        lblType5.Text = TypeName;
                        break;
                    case 6:
                        lblType6.Text = TypeName;
                        break;
                    case 7:
                        lblType7.Text = TypeName;
                        break;
                    case 8:
                        lblType8.Text = TypeName;
                        break;
                    case 9:
                        lblType9.Text = TypeName;
                        break;
                    case 10:
                        lblType10.Text = TypeName;
                        break;
                    case 11:
                        lblType11.Text = TypeName;
                        break;
                    case 12:
                        lblType12.Text = TypeName;
                        break;
                    case 13:
                        lblType13.Text = TypeName;
                        break;
                    case 14:
                        lblType14.Text = TypeName;
                        break;
                    case 15:
                        lblType15.Text = TypeName;
                        break;
                    case 16:
                        lblType16.Text = TypeName;
                        break;
                    case 17:
                        lblType17.Text = TypeName;
                        break;
                    case 18:
                        lblType18.Text = TypeName;
                        break;
                    case 19:
                        lblType19.Text = TypeName;
                        break;
                    case 20:
                        lblType20.Text = TypeName;
                        break;
                    case 21:
                        lblType21.Text = TypeName;
                        break;
                    case 22:
                        lblType22.Text = TypeName;
                        break;
                    case 23:
                        lblType23.Text = TypeName;
                        break;
                    case 24:
                        lblType24.Text = TypeName;
                        break;
                    case 25:
                        lblType25.Text = TypeName;
                        break;
                    case 26:
                        lblType26.Text = TypeName;
                        break;
                    case 27:
                        lblType27.Text = TypeName;
                        break;
                    case 28:
                        lblType28.Text = TypeName;
                        break;
                    case 29:
                        lblType29.Text = TypeName;
                        break;
                    case 30:
                        lblType30.Text = TypeName;
                        break;
                    case 31:
                        lblType31.Text = TypeName;
                        break;
                    case 32:
                        lblType32.Text = TypeName;
                        break;
                    case 33:
                        lblType33.Text = TypeName;
                        break;
                    case 34:
                        lblType34.Text = TypeName;
                        break;
                    case 35:
                        lblType35.Text = TypeName;
                        break;
                    case 36:
                        lblType36.Text = TypeName;
                        break;
                    case 37:
                        lblType37.Text = TypeName;
                        break;
                    case 38:
                        lblType38.Text = TypeName;
                        break;
                    case 39:
                        lblType39.Text = TypeName;
                        break;
                    case 40:
                        lblType40.Text = TypeName;
                        break;
                    case 41:
                        lblType41.Text = TypeName;
                        break;
                    case 42:
                        lblType42.Text = TypeName;
                        break;
                    case 43:
                        lblType43.Text = TypeName;
                        break;
                    case 44:
                        lblType44.Text = TypeName;
                        break;
                    case 45:
                        lblType45.Text = TypeName;
                        break;
                    case 46:
                        lblType46.Text = TypeName;
                        break;
                    case 47:
                        lblType47.Text = TypeName;
                        break;
                    case 48:
                        lblType48.Text = TypeName;
                        break;
                    case 49:
                        lblType49.Text = TypeName;
                        break;
                    case 50:
                        lblType50.Text = TypeName;
                        break;
                    case 51:
                        lblType51.Text = TypeName;
                        break;
                    case 52:
                        lblType52.Text = TypeName;
                        break;
                    case 53:
                        lblType53.Text = TypeName;
                        break;
                    case 54:
                        lblType54.Text = TypeName;
                        break;
                    case 55:
                        lblType55.Text = TypeName;
                        break;
                    case 56:
                        lblType56.Text = TypeName;
                        break;
                    case 57:
                        lblType57.Text = TypeName;
                        break;
                    case 58:
                        lblType58.Text = TypeName;
                        break;
                    case 59:
                        lblType59.Text = TypeName;
                        break;
                    case 60:
                        lblType60.Text = TypeName;
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 加载不需要上传的附件类型
        /// </summary>
        /// <param name="ds"></param>
        private void LoadFileSet(DataSet ds)
        {
            
            int ID = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                string url = "~/Part/image/3.png";
                try
                {
                    ID = int.Parse(dr["sx"].ToString());
                }
                catch (Exception)
                {
                    ID = 0;
                }
                switch (ID)
                {
                    case 1:
                        img1.ImageUrl = url;
                        break;
                    case 2:
                        img2.ImageUrl = url;
                        break;
                    case 3:
                        img3.ImageUrl = url;
                        break;
                    case 4:
                        img4.ImageUrl = url;
                        break;
                    case 5:
                        img5.ImageUrl = url;
                        break;
                    case 6:
                        img6.ImageUrl = url;
                        break;
                    case 7:
                        img7.ImageUrl = url;
                        break;
                    case 8:
                        img8.ImageUrl = url;
                        break;
                    case 9:
                        img9.ImageUrl = url;
                        break;
                    case 10:
                        img10.ImageUrl = url;
                        break;
                    case 11:
                        img11.ImageUrl = url;
                        break;
                    case 12:
                        img12.ImageUrl = url;
                        break;
                    case 13:
                        img13.ImageUrl = url;
                        break;
                    case 14:
                        img14.ImageUrl = url;
                        break;
                    case 15:
                        img15.ImageUrl = url;
                        break;
                    case 16:
                        img16.ImageUrl = url;
                        break;
                    case 17:
                        img17.ImageUrl = url;
                        break;
                    case 18:
                        img18.ImageUrl = url;
                        break;
                    case 19:
                        img19.ImageUrl = url;
                        break;
                    case 20:
                        img20.ImageUrl = url;
                        break;
                    case 21:
                        img21.ImageUrl = url;
                        break;
                    case 22:
                        img22.ImageUrl = url;
                        break;
                    case 23:
                        img23.ImageUrl = url;
                        break;
                    case 24:
                        img24.ImageUrl = url;
                        break;
                    case 25:
                        img25.ImageUrl = url;
                        break;
                    case 26:
                        img26.ImageUrl = url;
                        break;
                    case 27:
                        img27.ImageUrl = url;
                        break;
                    case 28:
                        img28.ImageUrl = url;
                        break;
                    case 29:
                        img29.ImageUrl = url;
                        break;
                    case 30:
                        img30.ImageUrl = url;
                        break;
                    case 31:
                        img31.ImageUrl = url;
                        break;
                    case 32:
                        img32.ImageUrl = url;
                        break;
                    case 33:
                        img33.ImageUrl = url;
                        break;
                    case 34:
                        img34.ImageUrl = url;
                        break;
                    case 35:
                        img35.ImageUrl = url;
                        break;
                    case 36:
                        img36.ImageUrl = url;
                        break;
                    case 37:
                        img37.ImageUrl = url;
                        break;
                    case 38:
                        img38.ImageUrl = url;
                        break;
                    case 39:
                        img39.ImageUrl = url;
                        break;
                    case 40:
                        img40.ImageUrl = url;
                        break;
                    case 41:
                        img41.ImageUrl = url;
                        break;
                    case 42:
                        img42.ImageUrl = url;
                        break;
                    case 43:
                        img43.ImageUrl = url;
                        break;
                    case 44:
                        img44.ImageUrl = url;
                        break;
                    case 45:
                        img45.ImageUrl = url;
                        break;
                    case 46:
                        img46.ImageUrl = url;
                        break;
                    case 47:
                        img47.ImageUrl = url;
                        break;
                    case 48:
                        img48.ImageUrl = url;
                        break;
                    case 49:
                        img49.ImageUrl = url;
                        break;
                    case 50:
                        img50.ImageUrl = url;
                        break;
                    case 51:
                        img51.ImageUrl = url;
                        break;
                    case 52:
                        img52.ImageUrl = url;
                        break;
                    case 53:
                        img53.ImageUrl = url;
                        break;
                    case 54:
                        img54.ImageUrl = url;
                        break;
                    case 55:
                        img55.ImageUrl = url;
                        break;
                    case 56:
                        img56.ImageUrl = url;
                        break;
                    case 57:
                        img57.ImageUrl = url;
                        break;
                    case 58:
                        img58.ImageUrl = url;
                        break;
                    case 59:
                        img59.ImageUrl = url;
                        break;
                    case 60:
                        img60.ImageUrl = url;
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 更新已上传图片
        /// </summary>
        /// <param name="ds"></param>
        private void LoadImg(DataSet ds)
        {
           
            string url = "~/Part/image/2.png";
            int ID = 0;
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                try
                {
                    ID = int.Parse(dr["rid"].ToString());
                    ID = int.Parse(dr["sx"].ToString());
                }
                catch (Exception)
                {
                    ID = 0;
                }
                switch (ID)
                {
                    case 1:
                        img1.ImageUrl = url;
                        break;
                    case 2:
                        img2.ImageUrl = url;
                        break;
                    case 3:
                        img3.ImageUrl = url;
                        break;
                    case 4:
                        img4.ImageUrl = url;
                        break;
                    case 5:
                        img5.ImageUrl = url;
                        break;
                    case 6:
                        img6.ImageUrl = url;
                        break;
                    case 7:
                        img7.ImageUrl = url;
                        break;
                    case 8:
                        img8.ImageUrl = url;
                        break;
                    case 9:
                        img9.ImageUrl = url;
                        break;
                    case 10:
                        img10.ImageUrl = url;
                        break;
                    case 11:
                        img11.ImageUrl = url;
                        break;
                    case 12:
                        img12.ImageUrl = url;
                        break;
                    case 13:
                        img13.ImageUrl = url;
                        break;
                    case 14:
                        img14.ImageUrl = url;
                        break;
                    case 15:
                        img15.ImageUrl = url;
                        break;
                    case 16:
                        img16.ImageUrl = url;
                        break;
                    case 17:
                        img17.ImageUrl = url;
                        break;
                    case 18:
                        img18.ImageUrl = url;
                        break;
                    case 19:
                        img19.ImageUrl = url;
                        break;
                    case 20:
                        img20.ImageUrl = url;
                        break;
                    case 21:
                        img21.ImageUrl = url;
                        break;
                    case 22:
                        img22.ImageUrl = url;
                        break;
                    case 23:
                        img23.ImageUrl = url;
                        break;
                    case 24:
                        img24.ImageUrl = url;
                        break;
                    case 25:
                        img25.ImageUrl = url;
                        break;
                    case 26:
                        img26.ImageUrl = url;
                        break;
                    case 27:
                        img27.ImageUrl = url;
                        break;
                    case 28:
                        img28.ImageUrl = url;
                        break;
                    case 29:
                        img29.ImageUrl = url;
                        break;
                    case 30:
                        img30.ImageUrl = url;
                        break;
                    case 31:
                        img31.ImageUrl = url;
                        break;
                    case 32:
                        img32.ImageUrl = url;
                        break;
                    case 33:
                        img33.ImageUrl = url;
                        break;
                    case 34:
                        img34.ImageUrl = url;
                        break;
                    case 35:
                        img35.ImageUrl = url;
                        break;
                    case 36:
                        img36.ImageUrl = url;
                        break;
                    case 37:
                        img37.ImageUrl = url;
                        break;
                    case 38:
                        img38.ImageUrl = url;
                        break;
                    case 39:
                        img39.ImageUrl = url;
                        break;
                    case 40:
                        img40.ImageUrl = url;
                        break;
                    case 41:
                        img41.ImageUrl = url;
                        break;
                    case 42:
                        img42.ImageUrl = url;
                        break;
                    case 43:
                        img43.ImageUrl = url;
                        break;
                    case 44:
                        img44.ImageUrl = url;
                        break;
                    case 45:
                        img45.ImageUrl = url;
                        break;
                    case 46:
                        img46.ImageUrl = url;
                        break;
                    case 47:
                        img47.ImageUrl = url;
                        break;
                    case 48:
                        img48.ImageUrl = url;
                        break;
                    case 49:
                        img49.ImageUrl = url;
                        break;
                    case 50:
                        img50.ImageUrl = url;
                        break;
                    case 51:
                        img51.ImageUrl = url;
                        break;
                    case 52:
                        img52.ImageUrl = url;
                        break;
                    case 53:
                        img53.ImageUrl = url;
                        break;
                    case 54:
                        img54.ImageUrl = url;
                        break;
                    case 55:
                        img55.ImageUrl = url;
                        break;
                    case 56:
                        img56.ImageUrl = url;
                        break;
                    case 57:
                        img57.ImageUrl = url;
                        break;
                    case 58:
                        img58.ImageUrl = url;
                        break;
                    case 59:
                        img59.ImageUrl = url;
                        break;
                    case 60:
                        img60.ImageUrl = url;
                        break;
                    //case 30:
                    //    img30.ImageUrl = url;
                    //    break;
                    default:
                        break;
                }

            }
           
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            img1.ImageUrl = img2.ImageUrl = img3.ImageUrl = img4.ImageUrl = img5.ImageUrl = img6.ImageUrl = img7.ImageUrl = img8.ImageUrl = img9.ImageUrl = img10.ImageUrl =
               img11.ImageUrl = img12.ImageUrl = img13.ImageUrl = img14.ImageUrl = img15.ImageUrl = img16.ImageUrl = img17.ImageUrl = img18.ImageUrl = img19.ImageUrl = img20.ImageUrl =
               img21.ImageUrl = img22.ImageUrl = img23.ImageUrl = img24.ImageUrl = img25.ImageUrl = img26.ImageUrl = img27.ImageUrl = img28.ImageUrl = img29.ImageUrl = img30.ImageUrl=
            img31.ImageUrl=img32.ImageUrl=img33.ImageUrl=img34.ImageUrl=img35.ImageUrl=img36.ImageUrl=img37.ImageUrl=img38.ImageUrl=img39.ImageUrl=img40.ImageUrl=img41.ImageUrl=img42.ImageUrl=
            img43.ImageUrl=img44.ImageUrl=img45.ImageUrl=img46.ImageUrl=img47.ImageUrl=img48.ImageUrl=img49.ImageUrl=img50.ImageUrl=img51.ImageUrl=img52.ImageUrl=img53.ImageUrl=img54.ImageUrl=
            img55.ImageUrl=img56.ImageUrl=img57.ImageUrl=img58.ImageUrl=img59.ImageUrl=img60.ImageUrl= "~/Part/image/1.png";
            DataSet ds = null;
            //if (DropDownList1.SelectedValue == "3")
            //{
                ds = sbo.GetList("  type=" + DropDownList1.SelectedValue + " and pparid=" + Request.QueryString["RID"].ToString());
                if (ds.Tables[0].Rows.Count == 0)
                    ds = typebo.GetIsLevel(DropDownList1.SelectedValue);
            //}
            //else
            //    ds = typebo.GetIsLevel(DropDownList1.SelectedValue);
            int ID = 0;
            string url = "~/Part/image/2.png";
            string url2 = "~/Part/image/3.png";
            //img1.Visible = img2.Visible = img3.Visible = img4.Visible = img5.Visible = img6.Visible = img7.Visible = img8.Visible = img9.Visible
            //    = img10.Visible = img11.Visible = img12.Visible = img13.Visible = img14.Visible = img15.Visible = img16.Visible = img17.Visible = img18.Visible
            //    = img10.Visible = img20.Visible = img21.Visible = img22.Visible = img23.Visible = img24.Visible = img25.Visible = img26.Visible = img17.Visible = img28.Visible=img29.Visible=img30.Visible = true;
            DataSet ids = ibo.GetList(" pparid=" + Request.QueryString["RID"].ToString());
            LoadFileSet(ids);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                try
                {
                    ID = int.Parse(dr["rid"].ToString());
                    ID = int.Parse(dr["sx"].ToString());
                }
                catch (Exception)
                {
                    ID = 0;
                }
                switch (ID)
                {
                    case 1:
                        if (img1.ImageUrl != url )
                            //img1.Visible = false;
                        img1.ImageUrl = url2;
                        break;
                    case 2:
                        if (img2.ImageUrl != url )
                            //img2.Visible = false;
                            img2.ImageUrl = url2;
                        break;
                    case 3:
                        if (img3.ImageUrl != url )
                           // img3.Visible = false;
                            img3.ImageUrl = url2;
                        break;
                    case 4:
                        if (img4.ImageUrl != url )
                            //img4.Visible = false;
                            img4.ImageUrl = url2;
                        break;
                    case 5:
                        if (img5.ImageUrl != url)
                           // img5.Visible = false;
                            img5.ImageUrl = url2;
                        break;
                    case 6:
                        if (img6.ImageUrl != url )
                            //img6.Visible = false;
                            img6.ImageUrl = url2;
                        break;
                    case 7:
                        if (img7.ImageUrl != url )
                           // img7.Visible = false;
                            img7.ImageUrl = url2;
                        break;
                    case 8:
                        if (img8.ImageUrl != url )
                           // img8.Visible = false;
                            img8.ImageUrl = url2;
                        break;
                    case 9:
                        if (img9.ImageUrl != url )
                           // img9.Visible = false;
                            img9.ImageUrl = url2;
                        break;
                    case 10:
                        if (img10.ImageUrl != url )
                           // img10.Visible = false;
                            img10.ImageUrl = url2;
                        break;
                    case 11:
                        if (img11.ImageUrl != url )
                            //img11.Visible = false;
                            img11.ImageUrl = url2;
                        break;
                    case 12:
                        if (img12.ImageUrl != url )
                           // img12.Visible = false;
                            img12.ImageUrl = url2;
                        break;
                    case 13:
                        if (img13.ImageUrl != url )
                           // img13.Visible = false;
                            img13.ImageUrl = url2;
                        break;
                    case 14:
                        if (img14.ImageUrl != url )
                            //img14.Visible = false;
                        img14.ImageUrl = url2;
                        break;
                    case 15:
                        if (img15.ImageUrl != url )
                           // img15.Visible = false;
                            img15.ImageUrl = url2;
                        break;
                    case 16:
                        if (img16.ImageUrl != url )
                            //img16.Visible = false;
                            img16.ImageUrl = url2;
                        break;
                    case 17:
                        if (img17.ImageUrl != url )
                            //img17.Visible = false;
                            img17.ImageUrl = url2;
                        break;
                    case 18:
                        if (img18.ImageUrl != url )
                            //img18.Visible = false;
                            img18.ImageUrl = url2;
                        break;
                    case 19:
                        if (img19.ImageUrl != url )
                           // img19.Visible = false;
                            img19.ImageUrl = url2;
                        break;
                    case 20:
                        if (img20.ImageUrl != url )
                           // img20.Visible = false;
                        img20.ImageUrl = url2;
                        break;
                    case 21:
                        if (img21.ImageUrl != url )
                            //img21.Visible = false;
                            img21.ImageUrl = url2;
                        break;
                    case 22:
                        if (img22.ImageUrl != url )
                           // img22.Visible = false;
                        img22.ImageUrl = url2;
                        break;
                    case 23:
                        if (img23.ImageUrl != url )
                           // img23.Visible = false;
                            img23.ImageUrl = url2;
                        break;
                    case 24:
                        if (img24.ImageUrl != url )
                            //img24.Visible = false;
                            img24.ImageUrl = url2;
                        break;
                    case 25:
                        if (img25.ImageUrl != url )
                            //img25.Visible = false;
                            img25.ImageUrl = url2;
                        break;
                    case 26:
                        if (img26.ImageUrl != url )
                           // img26.Visible = false;
                            img26.ImageUrl = url2;
                        break;
                    case 27:
                        if (img27.ImageUrl != url )
                           // img27.Visible = false;
                            img27.ImageUrl = url2;
                        break;
                    case 28:
                        if (img28.ImageUrl != url )
                            //img28.Visible = false;
                            img28.ImageUrl = url2;
                        break;
                    case 29:
                        if (img29.ImageUrl != url )
                           // img29.Visible = false;
                            img29.ImageUrl = url2;
                        break;
                    case 30:
                        if (img30.ImageUrl != url )
                           // img30.Visible = false;
                            img30.ImageUrl = url2;
                        break;
                    case 31:
                        if (img31.ImageUrl != url)
                            // img31.Visible = false;
                            img31.ImageUrl = url2;
                        break;
                    case 32:
                        if (img32.ImageUrl != url)
                            // img32.Visible = false;
                            img32.ImageUrl = url2;
                        break;
                    case 33:
                        if (img33.ImageUrl != url)
                            // img33.Visible = false;
                            img33.ImageUrl = url2;
                        break;
                    case 34:
                        if (img34.ImageUrl != url)
                            // img34.Visible = false;
                            img34.ImageUrl = url2;
                        break;
                    case 35:
                        if (img35.ImageUrl != url)
                            // img35.Visible = false;
                            img35.ImageUrl = url2;
                        break;
                    case 36:
                        if (img36.ImageUrl != url)
                            // img36.Visible = false;
                            img36.ImageUrl = url2;
                        break;
                    case 37:
                        if (img37.ImageUrl != url)
                            // img37.Visible = false;
                            img37.ImageUrl = url2;
                        break;
                    case 38:
                        if (img38.ImageUrl != url)
                            // img38.Visible = false;
                            img38.ImageUrl = url2;
                        break;
                    case 39:
                        if (img39.ImageUrl != url)
                            // img39.Visible = false;
                            img39.ImageUrl = url2;
                        break;
                    case 40:
                        if (img40.ImageUrl != url)
                            // img40.Visible = false;
                            img40.ImageUrl = url2;
                        break;
                    case 41:
                        if (img41.ImageUrl != url)
                            // img41.Visible = false;
                            img41.ImageUrl = url2;
                        break;
                    case 42:
                        if (img42.ImageUrl != url)
                            // img42.Visible = false;
                            img42.ImageUrl = url2;
                        break;
                    case 43:
                        if (img43.ImageUrl != url)
                            // img43.Visible = false;
                            img43.ImageUrl = url2;
                        break;
                    case 44:
                        if (img44.ImageUrl != url)
                            // img44.Visible = false;
                            img44.ImageUrl = url2;
                        break;
                    case 45:
                        if (img45.ImageUrl != url)
                            // img45.Visible = false;
                            img45.ImageUrl = url2;
                        break;
                    case 46:
                        if (img46.ImageUrl != url)
                            // img46.Visible = false;
                            img46.ImageUrl = url2;
                        break;
                    case 47:
                        if (img47.ImageUrl != url)
                            // img47.Visible = false;
                            img47.ImageUrl = url2;
                        break;
                    case 48:
                        if (img48.ImageUrl != url)
                            // img48.Visible = false;
                            img48.ImageUrl = url2;
                        break;
                    case 49:
                        if (img49.ImageUrl != url)
                            // img49.Visible = false;
                            img49.ImageUrl = url2;
                        break;
                    case 50:
                        if (img50.ImageUrl != url)
                            // img50.Visible = false;
                            img50.ImageUrl = url2;
                        break;
                    case 51:
                        if (img51.ImageUrl != url)
                            // img51.Visible = false;
                            img51.ImageUrl = url2;
                        break;
                    case 52:
                        if (img52.ImageUrl != url)
                            // img52.Visible = false;
                            img52.ImageUrl = url2;
                        break;
                    case 53:
                        if (img53.ImageUrl != url)
                            // img53.Visible = false;
                            img53.ImageUrl = url2;
                        break;
                    case 54:
                        if (img54.ImageUrl != url)
                            // img54.Visible = false;
                            img54.ImageUrl = url2;
                        break;
                    case 55:
                        if (img55.ImageUrl != url)
                            // img55.Visible = false;
                            img55.ImageUrl = url2;
                        break;
                    case 56:
                        if (img56.ImageUrl != url)
                            // img56.Visible = false;
                            img56.ImageUrl = url2;
                        break;
                    case 57:
                        if (img57.ImageUrl != url)
                            // img57.Visible = false;
                            img57.ImageUrl = url2;
                        break;
                    case 58:
                        if (img58.ImageUrl != url)
                            // img58.Visible = false;
                            img58.ImageUrl = url2;
                        break;
                    case 59:
                        if (img59.ImageUrl != url)
                            // img59.Visible = false;
                            img59.ImageUrl = url2;
                        break;
                    case 60:
                        if (img60.ImageUrl != url)
                            // img60.Visible = false;
                            img60.ImageUrl = url2;
                        break;
                    default:
                        break;
                }

            }

            PPAR p = ppbo.GetModel(int.Parse(Request.QueryString["RID"] == null ? "0" : Request.QueryString["RID"].ToString()));
            if (p != null)
            {
                // DropDownList1.SelectedValue = p.SUBMISSIONLEVEL.ToString();
                lblApp.Text = "<input type='button' width='106px'  class='button1' onclick='javascript:PopUpWindow(\"InapplicableSet.aspx?RID=" + p.ID + "\", 230, 60, 880, 550);'   value='Inapplicable'/>";
                if (p.STATUS == 0 || p.STATUS == 1 || p.STATUS == 4)
                {
                    ta1.Visible = false;
                    GridView2.Visible = false;
                   // lblApp.Visible = false;

                }

                FJRID = p.FJID;
                QEFJID = p.QEFJID;
                ShowData(p.FJID);
                ShowDataQE(QEFJID);

                p.SUBMISSIONLEVEL = int.Parse(DropDownList1.SelectedValue);
                p.ISSPECIFICATIONS = rbtYes.Checked ? 1 : 0;
                if (rbtYes.Checked) p.ISSPECIFICATIONS = 1;
                else if (rbtNo.Checked) p.ISSPECIFICATIONS = 0;
                else
                    p.ISSPECIFICATIONS = 2;
                int num = new PPARBO().UpdateForSupplierFJ(p);
            }

        }

        #endregion

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            lblErrMessage.Text = "";
            if (rbtNo.Checked && txtSpecify.Text.Trim() == "")
            {
                AlertMessage("Please input 'Specify your deviation(s)'");
                return;
            }
            PPAR p = ppbo.GetModel(int.Parse(Request.QueryString["RID"] == null ? "0" : Request.QueryString["RID"].ToString()));
            if (p != null)
            {
                if (p.STATUS == 0)
                    Page.RegisterStartupScript("AlertRedirect", "<script language='javascript'>alert(\"Please first save PPAP\");</script>");
                //Page.RegisterStartupScript("AlertMessage", "<script language='javascript'>alert('Please first save PPAP');return false;</script>");
                else if (p.ISWITHOUTSAMPLE == 0 && (p.DELIVERYPQ == ""||p.DELIVERYPQ=="-1" || p.DELIVERYCOMPANY == "" || p.DELIVERYNOTENUMBER == "" || p.DELIVERYNOTEDATE == DateTime.Parse("1900-01-01")))
                {
                    Page.RegisterStartupScript("AlertRedirect", "<script language='javascript'>alert(\"Please enter the logistics information\");</script>");
                }
                else
                {
                    DataSet ds = manager.GetFileList(p.FJID);
                    if (ds.Tables[0].Rows.Count == 0)
                    {
                        Page.RegisterStartupScript("AlertRedirect", "<script language='javascript'>alert(\"No upload attachment\");</script>");
                    }
                    else
                    {
                        MailTemplate mail = mbo.GetModel(2);
                        DataSet dsmail = mbo.GetEDM2(p.ID.ToString());
                        if (mail != null && dsmail.Tables[0].Rows.Count > 0)
                        {
                            string title = mail.TITLE.Replace("{Part No.}", dsmail.Tables[0].Rows[0]["bdntpartno"].ToString());
                            title = title.Replace("{Part name}", dsmail.Tables[0].Rows[0]["bdntpartname"].ToString());
                            title = title.Replace("{Color}", dsmail.Tables[0].Rows[0]["color"].ToString());
                            try
                            {
                                base.SendEmailToUser(dsmail.Tables[0].Rows[0]["email"].ToString(), title, mail.CONTENT, null);
                                lbo.WriteLog(CurrentUser.Id, "Send Email:" + dsmail.Tables[0].Rows[0]["email"].ToString(), Request.QueryString["rid"].ToString());

                            }
                            catch (Exception ex)
                            {
                                AlertMessage(ex.Message.ToString());
                                lblErrMessage.Text = ex.Message.ToString();
                                lbo.WriteLog(CurrentUser.Id, "Send Email:" + ex.Message.ToString(), Request.QueryString["rid"].ToString());
                            }
                            p.STATUS = 2;
                            p.Submittedby = CurrentUser.Id;
                            p.SUBMISSIONLEVEL = int.Parse(DropDownList1.SelectedValue);
                            p.ISSPECIFICATIONS = rbtYes.Checked ? 1 : 0;
                            p.ISCAPABILITYDOCUMENT = 1;
                            p.ISCAPABILITYPART = 1;
                            p.CAPABILITYFEEDBACK = "";
                            p.SPECIFY = txtSpecify.Text.Trim();
                            int num = new PPARBO().UpdateForSupplier(p);
                            lbo.WriteLog(CurrentUser.Id, "Submit PPAR", Request.QueryString["RID"].ToString());
                            if (num > 0)
                            {
                                Response.Write("<script language=javascript>top.frames['menu'].location.reload();</script>");
                                Response.Write("<script>top.frames['mainFrame'].location='PPAPTasks.aspx'</script>");
                            }
                        }

                    }
                }
            }
        }

        /// <summary>
        /// 获取连接
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public string GetLink(string filename)
        {
            //string filepath = "ftp://" + ConfigurationManager.AppSettings["ftpServerIP"] + "/";
            string filepath = ConfigurationManager.AppSettings["FilePath"];
            return filepath + filename;

        }

        ///// <summary>
        ///// 截取文件名
        ///// </summary>
        ///// <param name="filename"></param>
        ///// <returns></returns>
        //public string GetLinkSub(string filename)
        //{
        //    if(filename.Length>14)
        //        return filename.Substring(14,filename.Length-1)

        //}

        protected void LinkButton2_Click(object sender, EventArgs e)
        {
            LinkButton link = (LinkButton)sender;
            if (File.Exists(ConfigurationManager.AppSettings["FilePath"] + link.ToolTip))
            {
                FileInfo file = new FileInfo(ConfigurationManager.AppSettings["FilePath"] + link.ToolTip);
                Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8"); //解决中文乱码
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name.Length>14?file.Name.Substring(14,file.Name.Length-14):file.Name)); //解决中文文件名乱码    
                Response.AddHeader("Content-length", file.Length.ToString());
                Response.ContentType = "appliction/octet-stream";
                Response.WriteFile(file.FullName);
                Response.End();
            }
            else
                AlertMessage("File does not exist");
        }

        protected void rbtYes_CheckedChanged(object sender, EventArgs e)
        {
            PPAR p = ppbo.GetModel(int.Parse(Request.QueryString["RID"] == null ? "0" : Request.QueryString["RID"].ToString()));
            if (p != null)
            {
                p.SUBMISSIONLEVEL = int.Parse(DropDownList1.SelectedValue);
                p.ISSPECIFICATIONS = rbtYes.Checked ? 1 : 0;
                p.SPECIFY = txtSpecify.Text;
                int num = new PPARBO().UpdateForSupplierFJ(p);

            }
            specify.Visible = rbtYes.Checked ? false : rbtNo.Checked ? true : false;
        }


        /// <summary>
        /// 模版有效性
        /// </summary>
        /// <param name="ds"></param>
        private void LoadFileSet3(DataSet ds)
        {
            int ID = 0;
            string check = "";
            string uid = "";
            string name = "";
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                ID = int.Parse(dr["sx"].ToString());
                //ID = int.Parse(dr["rownum"].ToString());
                check = dr["bdnttemplateavailable"].ToString() == "1" ? "<font style='font-size:14px; font-weight:bold; background-color:#0066FF;margin-top:10px; margin-bottom:10px;' color='#FFFFFF'>&nbsp;&nbsp;Y&nbsp;&nbsp;</font>" : "<font style='font-size:14px; font-weight:bold; background-color:#C6C5C3;margin-top:10px; margin-bottom:10px;' color='#FFFFFF'>&nbsp;&nbsp;N&nbsp;&nbsp;</font>";
                uid = dr["uploadedfile"].ToString();
                name = dr["ATTACHMENTTYPE"].ToString();
                switch (ID)
                {
                    case 1:
                        lb1.Text = check;
                        lb1.CssClass = uid;
                        lb1.ToolTip = name;

                        img1.Visible = true;
                        lbnum1.Visible = true;
                        lblType1.Visible = true;
                        lb1.Visible = true;

                        tr1.Visible = true;
                        break;
                    case 2:
                        lb2.Text = check;
                        lb2.CssClass = uid;
                        lb2.ToolTip = name;

                        img2.Visible = true;
                        lbnum2.Visible = true;
                        lblType2.Visible = true;
                        lb2.Visible = true;

                        tr1.Visible = true;
                        break;
                    case 3:
                        lb3.Text = check;
                        lb3.CssClass = uid;
                        lb3.ToolTip = name;

                        img3.Visible = true;
                        lbnum3.Visible = true;
                        lblType3.Visible = true;
                        lb3.Visible = true;

                        tr1.Visible = true;
                        break;
                    case 4:
                        lb4.Text = check;
                        lb4.CssClass = uid;
                        lb4.ToolTip = name;

                        img4.Visible = true;
                        lbnum4.Visible = true;
                        lblType4.Visible = true;
                        lb4.Visible = true;

                        tr2.Visible = true;
                        break;
                    case 5:
                        lb5.Text = check;
                        lb5.CssClass = uid;
                        lb5.ToolTip = name;

                        img5.Visible = true;
                        lbnum5.Visible = true;
                        lblType5.Visible = true;
                        lb5.Visible = true;

                        tr2.Visible = true;
                        break;
                    case 6:
                        lb6.Text = check;
                        lb6.CssClass = uid;
                        lb6.ToolTip = name;

                        img6.Visible = true;
                        lbnum6.Visible = true;
                        lblType6.Visible = true;
                        lb6.Visible = true;

                        tr2.Visible = true;
                        break;
                    case 7:
                        lb7.Text = check;
                        lb7.CssClass = uid;
                        lb7.ToolTip = name;

                        img7.Visible = true;
                        lbnum7.Visible = true;
                        lblType7.Visible = true;
                        lb7.Visible = true;

                        tr3.Visible = true;
                        break;
                    case 8:
                        lb8.Text = check;
                        lb8.CssClass = uid;
                        lb8.ToolTip = name;

                        img8.Visible = true;
                        lbnum8.Visible = true;
                        lblType8.Visible = true;
                        lb8.Visible = true;

                        tr3.Visible = true;
                        break;
                    case 9:
                        lb9.Text = check;
                        lb9.CssClass = uid;
                        lb9.ToolTip = name;

                        img9.Visible = true;
                        lbnum9.Visible = true;
                        lblType9.Visible = true;
                        lb9.Visible = true;

                        tr3.Visible = true;
                        break;
                    case 10:
                        lb10.Text = check;
                        lb10.CssClass = uid;
                        lb10.ToolTip = name;

                        img10.Visible = true;
                        lbnum10.Visible = true;
                        lblType10.Visible = true;
                        lb10.Visible = true;

                        tr4.Visible = true;
                        break;
                    case 11:
                        lb11.Text = check;
                        lb11.CssClass = uid;
                        lb11.ToolTip = name;

                        img11.Visible = true;
                        lbnum11.Visible = true;
                        lblType11.Visible = true;
                        lb11.Visible = true;

                        tr4.Visible = true;
                        break;
                    case 12:
                        lb12.Text = check;
                        lb12.CssClass = uid;
                        lb12.ToolTip = name;

                        img12.Visible = true;
                        lbnum12.Visible = true;
                        lblType12.Visible = true;
                        lb12.Visible = true;

                        tr4.Visible = true;
                        break;
                    case 13:
                        lb13.Text = check;
                        lb13.CssClass = uid;
                        lb13.ToolTip = name;

                        img13.Visible = true;
                        lbnum13.Visible = true;
                        lblType13.Visible = true;
                        lb13.Visible = true;

                        tr5.Visible = true;
                        break;
                    case 14:
                        lb14.Text = check;
                        lb14.CssClass = uid;
                        lb14.ToolTip = name;

                        img14.Visible = true;
                        lbnum14.Visible = true;
                        lblType14.Visible = true;
                        lb14.Visible = true;

                        tr5.Visible = true;
                        break;
                    case 15:
                        lb15.Text = check;
                        lb15.CssClass = uid;
                        lb15.ToolTip = name;

                        img15.Visible = true;
                        lbnum15.Visible = true;
                        lblType15.Visible = true;
                        lb15.Visible = true;

                        tr5.Visible = true;
                        break;
                    case 16:
                        lb16.Text = check;
                        lb16.CssClass = uid;
                        lb16.ToolTip = name;

                        img16.Visible = true;
                        lbnum16.Visible = true;
                        lblType16.Visible = true;
                        lb16.Visible = true;

                        tr6.Visible = true;
                        break;
                    case 17:
                        lb17.Text = check;
                        lb17.CssClass = uid;
                        lb17.ToolTip = name;

                        img17.Visible = true;
                        lbnum17.Visible = true;
                        lblType17.Visible = true;
                        lb17.Visible = true;

                        tr6.Visible = true;
                        break;
                    case 18:
                        lb18.Text = check;
                        lb18.CssClass = uid;
                        lb18.ToolTip = name;

                        img18.Visible = true;
                        lbnum18.Visible = true;
                        lblType18.Visible = true;
                        lb18.Visible = true;

                        tr6.Visible = true;
                        break;
                    case 19:
                        lb19.Text = check;
                        lb19.CssClass = uid;
                        lb19.ToolTip = name;

                        img19.Visible = true;
                        lbnum19.Visible = true;
                        lblType19.Visible = true;
                        lb19.Visible = true;

                        tr7.Visible = true;
                        break;
                    case 20:
                        lb20.Text = check;
                        lb20.CssClass = uid;
                        lb20.ToolTip = name;

                        img20.Visible = true;
                        lbnum20.Visible = true;
                        lblType20.Visible = true;
                        lb20.Visible = true;

                        tr7.Visible = true;
                        break;
                    case 21:
                        lb21.Text = check;
                        lb21.CssClass = uid;
                        lb21.ToolTip = name;

                        img21.Visible = true;
                        lbnum21.Visible = true;
                        lblType21.Visible = true;
                        lb21.Visible = true;

                        tr7.Visible = true;
                        break;
                    case 22:
                        lb22.Text = check;
                        lb22.CssClass = uid;
                        lb22.ToolTip = name;

                        img22.Visible = true;
                        lbnum22.Visible = true;
                        lblType22.Visible = true;
                        lb22.Visible = true;

                        tr8.Visible = true;
                        break;
                    case 23:
                        lb23.Text = check;
                        lb23.CssClass = uid;
                        lb23.ToolTip = name;

                        img23.Visible = true;
                        lbnum23.Visible = true;
                        lblType23.Visible = true;
                        lb23.Visible = true;

                        tr8.Visible = true;
                        break;
                    case 24:
                        lb24.Text = check;
                        lb24.CssClass = uid;
                        lb24.ToolTip = name;

                        img24.Visible = true;
                        lbnum24.Visible = true;
                        lblType24.Visible = true;
                        lb24.Visible = true;

                        tr8.Visible = true;
                        break;
                    case 25:
                        lb25.Text = check;
                        lb25.CssClass = uid;
                        lb25.ToolTip = name;

                        img25.Visible = true;
                        lbnum25.Visible = true;
                        lblType25.Visible = true;
                        lb25.Visible = true;

                        tr9.Visible = true;
                        break;
                    case 26:
                        lb26.Text = check;
                        lb26.CssClass = uid;
                        lb26.ToolTip = name;

                        img26.Visible = true;
                        lbnum26.Visible = true;
                        lblType26.Visible = true;
                        lb26.Visible = true;

                        tr9.Visible = true;
                        break;
                    case 27:
                        lb27.Text = check;
                        lb27.CssClass = uid;
                        lb27.ToolTip = name;

                        img27.Visible = true;
                        lbnum27.Visible = true;
                        lblType27.Visible = true;
                        lb27.Visible = true;

                        tr9.Visible = true;
                        break;
                    case 28:
                        lb28.Text = check;
                        lb28.CssClass = uid;
                        lb28.ToolTip = name;

                        img28.Visible = true;
                        lbnum28.Visible = true;
                        lblType28.Visible = true;
                        lb28.Visible = true;

                        tr10.Visible = true;
                        break;
                    case 29:
                        lb29.Text = check;
                        lb29.CssClass = uid;
                        lb29.ToolTip = name;

                        img29.Visible = true;
                        lbnum29.Visible = true;
                        lblType29.Visible = true;
                        lb29.Visible = true;

                        tr10.Visible = true;
                        break;
                    case 30:
                        lb30.Text = check;
                        lb30.CssClass = uid;
                        lb30.ToolTip = name;

                        img30.Visible = true;
                        lbnum30.Visible = true;
                        lblType30.Visible = true;
                        lb30.Visible = true;

                        tr10.Visible = true;
                        break;
                    case 31:
                        lb31.Text = check;
                        lb31.CssClass = uid;
                        lb31.ToolTip = name;

                        img31.Visible = true;
                        lbnum31.Visible = true;
                        lblType31.Visible = true;
                        lb31.Visible = true;

                        tr11.Visible = true;
                        break;
                    case 32:
                        lb32.Text = check;
                        lb32.CssClass = uid;
                        lb32.ToolTip = name;

                        img32.Visible = true;
                        lbnum32.Visible = true;
                        lblType32.Visible = true;
                        lb32.Visible = true;

                        tr11.Visible = true;
                        break;
                    case 33:
                        lb33.Text = check;
                        lb33.CssClass = uid;
                        lb33.ToolTip = name;

                        img33.Visible = true;
                        lbnum33.Visible = true;
                        lblType33.Visible = true;
                        lb33.Visible = true;

                        tr11.Visible = true;
                        break;
                    case 34:
                        lb34.Text = check;
                        lb34.CssClass = uid;
                        lb34.ToolTip = name;

                        img34.Visible = true;
                        lbnum34.Visible = true;
                        lblType34.Visible = true;
                        lb34.Visible = true;

                        tr12.Visible = true;
                        break;
                    case 35:
                        lb35.Text = check;
                        lb35.CssClass = uid;
                        lb35.ToolTip = name;

                        img35.Visible = true;
                        lbnum35.Visible = true;
                        lblType35.Visible = true;
                        lb35.Visible = true;

                        tr12.Visible = true;
                        break;
                    case 36:
                        lb36.Text = check;
                        lb36.CssClass = uid;
                        lb36.ToolTip = name;

                        img36.Visible = true;
                        lbnum36.Visible = true;
                        lblType36.Visible = true;
                        lb36.Visible = true;

                        tr12.Visible = true;
                        break;
                    case 37:
                        lb37.Text = check;
                        lb37.CssClass = uid;
                        lb37.ToolTip = name;

                        img37.Visible = true;
                        lbnum37.Visible = true;
                        lblType37.Visible = true;
                        lb37.Visible = true;

                        tr13.Visible = true;
                        break;
                    case 38:
                        lb38.Text = check;
                        lb38.CssClass = uid;
                        lb38.ToolTip = name;

                        img38.Visible = true;
                        lbnum38.Visible = true;
                        lblType38.Visible = true;
                        lb38.Visible = true;

                        tr13.Visible = true;
                        break;
                    case 39:
                        lb39.Text = check;
                        lb39.CssClass = uid;
                        lb39.ToolTip = name;

                        img39.Visible = true;
                        lbnum39.Visible = true;
                        lblType39.Visible = true;
                        lb39.Visible = true;

                        tr13.Visible = true;
                        break;
                    case 40:
                        lb40.Text = check;
                        lb40.CssClass = uid;
                        lb40.ToolTip = name;

                        img40.Visible = true;
                        lbnum40.Visible = true;
                        lblType40.Visible = true;
                        lb40.Visible = true;

                        tr14.Visible = true;
                        break;
                    case 41:
                        lb41.Text = check;
                        lb41.CssClass = uid;
                        lb41.ToolTip = name;

                        img41.Visible = true;
                        lbnum41.Visible = true;
                        lblType41.Visible = true;
                        lb41.Visible = true;

                        tr14.Visible = true;
                        break;
                    case 42:
                        lb42.Text = check;
                        lb42.CssClass = uid;
                        lb42.ToolTip = name;

                        img42.Visible = true;
                        lbnum42.Visible = true;
                        lblType42.Visible = true;
                        lb42.Visible = true;

                        tr14.Visible = true;
                        break;
                    case 43:
                        lb43.Text = check;
                        lb43.CssClass = uid;
                        lb43.ToolTip = name;

                        img43.Visible = true;
                        lbnum43.Visible = true;
                        lblType43.Visible = true;
                        lb43.Visible = true;

                        tr15.Visible = true;
                        break;
                    case 44:
                        lb44.Text = check;
                        lb44.CssClass = uid;
                        lb44.ToolTip = name;

                        img44.Visible = true;
                        lbnum44.Visible = true;
                        lblType44.Visible = true;
                        lb44.Visible = true;

                        tr15.Visible = true;
                        break;
                    case 45:
                        lb45.Text = check;
                        lb45.CssClass = uid;
                        lb45.ToolTip = name;

                        img45.Visible = true;
                        lbnum45.Visible = true;
                        lblType45.Visible = true;
                        lb45.Visible = true;

                        tr15.Visible = true;
                        break;
                    case 46:
                        lb46.Text = check;
                        lb46.CssClass = uid;
                        lb46.ToolTip = name;

                        img46.Visible = true;
                        lbnum46.Visible = true;
                        lblType46.Visible = true;
                        lb46.Visible = true;

                        tr16.Visible = true;
                        break;
                    case 47:
                        lb47.Text = check;
                        lb47.CssClass = uid;
                        lb47.ToolTip = name;

                        img47.Visible = true;
                        lbnum47.Visible = true;
                        lblType47.Visible = true;
                        lb47.Visible = true;

                        tr16.Visible = true;
                        break;
                    case 48:
                        lb48.Text = check;
                        lb48.CssClass = uid;
                        lb48.ToolTip = name;

                        img48.Visible = true;
                        lbnum48.Visible = true;
                        lblType48.Visible = true;
                        lb48.Visible = true;

                        tr16.Visible = true;
                        break;
                    case 49:
                        lb49.Text = check;
                        lb49.CssClass = uid;
                        lb49.ToolTip = name;

                        img49.Visible = true;
                        lbnum49.Visible = true;
                        lblType49.Visible = true;
                        lb49.Visible = true;

                        tr17.Visible = true;
                        break;
                    case 50:
                        lb50.Text = check;
                        lb50.CssClass = uid;
                        lb50.ToolTip = name;

                        img50.Visible = true;
                        lbnum50.Visible = true;
                        lblType50.Visible = true;
                        lb50.Visible = true;

                        tr17.Visible = true;
                        break;
                    case 51:
                        lb51.Text = check;
                        lb51.CssClass = uid;
                        lb51.ToolTip = name;

                        img51.Visible = true;
                        lbnum51.Visible = true;
                        lblType51.Visible = true;
                        lb51.Visible = true;

                        tr17.Visible = true;
                        break;
                    case 52:
                        lb52.Text = check;
                        lb52.CssClass = uid;
                        lb52.ToolTip = name;

                        img52.Visible = true;
                        lbnum52.Visible = true;
                        lblType52.Visible = true;
                        lb52.Visible = true;

                        tr18.Visible = true;
                        break;
                    case 53:
                        lb53.Text = check;
                        lb53.CssClass = uid;
                        lb53.ToolTip = name;

                        img53.Visible = true;
                        lbnum53.Visible = true;
                        lblType53.Visible = true;
                        lb53.Visible = true;

                        tr18.Visible = true;
                        break;
                    case 54:
                        lb54.Text = check;
                        lb54.CssClass = uid;
                        lb54.ToolTip = name;

                        img54.Visible = true;
                        lbnum54.Visible = true;
                        lblType54.Visible = true;
                        lb54.Visible = true;

                        tr18.Visible = true;
                        break;
                    case 55:
                        lb55.Text = check;
                        lb55.CssClass = uid;
                        lb55.ToolTip = name;

                        img55.Visible = true;
                        lbnum55.Visible = true;
                        lblType55.Visible = true;
                        lb55.Visible = true;

                        tr19.Visible = true;
                        break;
                    case 56:
                        lb56.Text = check;
                        lb56.CssClass = uid;
                        lb56.ToolTip = name;

                        img56.Visible = true;
                        lbnum56.Visible = true;
                        lblType56.Visible = true;
                        lb56.Visible = true;

                        tr19.Visible = true;
                        break;
                    case 57:
                        lb57.Text = check;
                        lb57.CssClass = uid;
                        lb57.ToolTip = name;

                        img57.Visible = true;
                        lbnum57.Visible = true;
                        lblType57.Visible = true;
                        lb57.Visible = true;

                        tr19.Visible = true;
                        break;
                    case 58:
                        lb58.Text = check;
                        lb58.CssClass = uid;
                        lb58.ToolTip = name;

                        img58.Visible = true;
                        lbnum58.Visible = true;
                        lblType58.Visible = true;
                        lb58.Visible = true;

                        tr20.Visible = true;
                        break;
                    case 59:
                        lb59.Text = check;
                        lb59.CssClass = uid;
                        lb59.ToolTip = name;

                        img59.Visible = true;
                        lbnum59.Visible = true;
                        lblType59.Visible = true;
                        lb59.Visible = true;

                        tr20.Visible = true;
                        break;
                    case 60:
                        lb60.Text = check;
                        lb60.CssClass = uid;
                        lb60.ToolTip = name;

                        img60.Visible = true;
                        lbnum60.Visible = true;
                        lblType60.Visible = true;
                        lb60.Visible = true;

                        tr20.Visible = true;
                        break;
                    default:
                        break;
                }
            }
        }

        /// <summary>
        /// 下载附件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void lb1_Click(object sender, EventArgs e)
        {
            try
            {
                LinkButton lb = (LinkButton)sender;
                if (lb.Text.Contains("Y"))
                {
                    string path = HttpContext.Current.Request.MapPath("../FileUpload/Template/" + lb.CssClass);
                    string file = HttpContext.Current.Request.MapPath("../FileUpload/Template/Template.zip");
                    if (File.Exists(file))
                    {
                        File.Delete(file);
                    }
                    DirectoryInfo upDir = new DirectoryInfo(path);
                    if (!upDir.Exists)
                    {
                        AlertMessage("Template not available currently.");
                        return;
                    }
                    Zip(path, file);
                    System.IO.FileInfo files = new System.IO.FileInfo(file);
                    string fileName = files.Name;
                    Response.Clear();
                    Response.AddHeader("Content-Disposition", "attachment; filename=" + lb.ToolTip + ".zip");
                    Response.AddHeader("Content-Length", files.Length.ToString());
                    Response.ContentType = "application/zip";
                    Response.WriteFile(files.FullName);
                    Response.Flush();
                }
                else
                {
                    AlertMessage("No template");
                    return;
                }
            }
            catch (Exception ex)
            {
                AlertMessage(ex.Message.ToString());
            }
        }






        /// <summary>
        /// 将文件压缩为zip文件
        /// </summary>
        /// <param name="FileToZip">原文件路径</param>
        /// <param name="ZipedFile">zip文件路径</param>
        public void ZipFile(string FileToZip, string ZipedFile)
        {
            //如果文件没有找到，则报错
            if (!File.Exists(FileToZip))
            {
                base.AlertMessage("地址错误");
                //throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
            }
            FileStream fs = File.OpenRead(FileToZip);
            byte[] buffer = new byte[fs.Length];
            fs.Read(buffer, 0, buffer.Length);
            fs.Close();

            FileStream ZipFile = File.Create(ZipedFile);
            ZipOutputStream ZipStream = new ZipOutputStream(ZipFile);
            ZipEntry ZipEntry = new ZipEntry("ZippedFile.txt");
            ZipStream.PutNextEntry(ZipEntry);
            ZipStream.SetLevel(6);

            ZipStream.Write(buffer, 0, buffer.Length);
            ZipStream.Finish();
            ZipStream.Close();

        }

        /// <summary>
        /// 递归压缩文件夹方法
        /// </summary>
        /// <param name="FolderToZip"></param>
        /// <param name="s"></param>
        /// <param name="ParentFolderName"></param>
        private bool ZipFileDictory(string FolderToZip, ZipOutputStream s, string ParentFolderName)
        {
            bool res = true;
            string[] folders, filenames;
            ZipEntry entry = null;
            FileStream fs = null;
            Crc32 crc = new Crc32();
            try
            {
                //创建当前文件夹
                entry = new ZipEntry(Path.Combine(ParentFolderName, Path.GetFileName(FolderToZip) + "/"));  //加上 “/” 才会当成是文件夹创建
                s.PutNextEntry(entry);
                s.Flush();
                //先压缩文件，再递归压缩文件夹 
                filenames = Directory.GetFiles(FolderToZip);
                foreach (string file in filenames)
                {
                    //打开压缩文件
                    fs = File.OpenRead(file);
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    entry = new ZipEntry(Path.Combine(ParentFolderName, Path.GetFileName(FolderToZip) + "/" + Path.GetFileName(file)));
                    entry.DateTime = DateTime.Now;
                    entry.Size = fs.Length;
                    fs.Close();
                    crc.Reset();
                    crc.Update(buffer);
                    entry.Crc = crc.Value;
                    s.PutNextEntry(entry);
                    s.Write(buffer, 0, buffer.Length);
                }
            }
            catch
            {
                res = false;
            }
            finally
            {
                if (fs != null)
                {
                    fs.Close();
                    fs = null;
                }
                if (entry != null)
                    entry = null;
                GC.Collect();
                GC.Collect(1);
            }
            folders = Directory.GetDirectories(FolderToZip);
            foreach (string folder in folders)
            {
                if (!ZipFileDictory(folder, s, Path.Combine(ParentFolderName, Path.GetFileName(FolderToZip))))
                    return false;
            }
            return res;
        }

        /// <summary>
        /// 压缩目录
        /// </summary>
        /// <param name="FolderToZip">待压缩的文件夹，全路径格式</param>
        /// <param name="ZipedFile">压缩后的文件名，全路径格式</param>
        /// <returns></returns>
        private bool ZipFileDictory(string FolderToZip, string ZipedFile, string Password)
        {
            bool res;
            if (!Directory.Exists(FolderToZip))
                return false;
            ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile));
            s.SetLevel(6);
            //			if (!string.IsNullOrEmpty(Password.Trim()))
            //				s.Password = Password.Trim();
            res = ZipFileDictory(FolderToZip, s, "");
            s.Finish();
            s.Close();
            return res;
        }

        /// <summary>
        /// 压缩文件
        /// </summary>
        /// <param name="FileToZip">要进行压缩的文件名</param>
        /// <param name="ZipedFile">压缩后生成的压缩文件名</param>
        /// <returns></returns>
        private bool ZipFile(string FileToZip, string ZipedFile, string Password)
        {
            //如果文件没有找到，则报错
            if (!File.Exists(FileToZip))
                throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!");
            //FileStream fs = null;
            FileStream ZipFile = null;
            ZipOutputStream ZipStream = null;
            ZipEntry ZipEntry = null;
            bool res = true;
            try
            {
                ZipFile = File.OpenRead(FileToZip);
                byte[] buffer = new byte[ZipFile.Length];
                ZipFile.Read(buffer, 0, buffer.Length);
                ZipFile.Close();
                ZipFile = File.Create(ZipedFile);
                ZipStream = new ZipOutputStream(ZipFile);
                //				if (!string.IsNullOrEmpty(Password.Trim()))
                //					ZipStream.Password = Password.Trim();
                ZipEntry = new ZipEntry(Path.GetFileName(FileToZip));
                ZipStream.PutNextEntry(ZipEntry);
                ZipStream.SetLevel(6);
                ZipStream.Write(buffer, 0, buffer.Length);
            }
            catch
            {
                res = false;
            }
            finally
            {
                if (ZipEntry != null)
                {
                    ZipEntry = null;
                }
                if (ZipStream != null)
                {
                    ZipStream.Finish();
                    ZipStream.Close();
                }
                if (ZipFile != null)
                {
                    ZipFile.Close();
                    ZipFile = null;
                }
                GC.Collect();
                GC.Collect(1);
            }
            return res;
        }

        /// <summary>
        /// 压缩文件 和 文件夹
        /// </summary>
        /// <param name="FileToZip">待压缩的文件或文件夹，全路径格式</param>
        /// <param name="ZipedFile">压缩后生成的压缩文件名，全路径格式</param>
        /// <param name="Password">压缩密码</param>
        /// <returns></returns>
        public bool Zip(string FileToZip, string ZipedFile, string Password)
        {
            if (Directory.Exists(FileToZip))
            {
                return ZipFileDictory(FileToZip, ZipedFile, Password);
            }
            else if (File.Exists(FileToZip))
            {
                return ZipFile(FileToZip, ZipedFile, Password);
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 压缩文件 和 文件夹
        /// </summary>
        /// <param name="FileToZip">待压缩的文件或文件夹，全路径格式</param>
        /// <param name="ZipedFile">压缩后生成的压缩文件名，全路径格式</param>
        /// <returns></returns>
        public bool Zip(string FileToZip, string ZipedFile)
        {
            return Zip(FileToZip, ZipedFile, "");
        }

        /// <summary>
        /// 自动保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void txtSpecify_TextChanged(object sender, EventArgs e)
        {
            PPAR p = ppbo.GetModel(int.Parse(Request.QueryString["RID"] == null ? "0" : Request.QueryString["RID"].ToString()));
            if (p != null)
            {
                p.SUBMISSIONLEVEL = int.Parse(DropDownList1.SelectedValue);
                p.ISSPECIFICATIONS = rbtYes.Checked ? 1 : 0;
                p.SPECIFY = txtSpecify.Text;
                int num = new PPARBO().UpdateForSupplierFJ(p);

            }
            specify.Visible = rbtYes.Checked ? false : rbtNo.Checked ? true : false;
        }


    }
}